home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
os2
/
mbase101.zip
/
dbtest.nrx
< prev
next >
Wrap
Text File
|
1996-12-18
|
7KB
|
235 lines
/* A simple netrexx program to test RXDbase. Forza Juve! */
options binary
import RXDbase
/* Here lies the variables declaration */
dbMine = RXDbase() /* instance which will handle the db */
rRec = Rexx[3,3] /* Used to store the record's structure -
the first '3' means that we have 2 fields here,
and the second is a fixed index (you always will
want to put '3' as the second index) */
rRec2 = Rexx[2] /* Used to handle (un)delete - we will delete only 1 item */
rArr = Rexx[3,3] /* Used to store data to be written in the archive */
rArr2 = Rexx[,] /* Used to retrieve data from the archive (could have done
it with rArr as well, but did this way for clarity) */
rFilter = Rexx[5]
rStats = Rexx[4] /* Used to gather stats on the db */
rTemp = Rexx '' /* Sorry, I got short of names */
rTemp2 = Rexx ''
rTemp3 = Rexx ''
rFileName = Rexx null /* The DB name */
iCount = int 0 /* counters used in the program */
iCount2 = int 0
/*
From now on, the body of the example.
If you get depressed learning by example, refer
to the docs. Life is wonderful.
*/
rFileName = 'db' /* Name of the db - I got imagination, heh? */
rRec[0,0] = 2 /* Number of fields */
rRec[1,0] = 12 /* The first field has size.. */
rRec[1,1] = 'Name' /* The first field has name.. */
rRec[1,2] = 'ISAM10' /* The indexing method: ISAM, accepting NULLs, but not duplicates */
rRec[2,0] = 12 /* The second field has size.. */
rRec[2,1] = 'Surname'/* The second field has name.. */
rRec[2,2] = 'ISAM01' /* The indexing method: Acceptin duplicates, but not NULLs */
/*
Delete previous db - it will report ERROR:FILE ACCESS PROBLEMS if no
db is found, but it's not a real problem.
*/
say 'Previous db deletion reported: 'dbMine.deletedb('db')
/* First of all, let's connect to the database */
say 'After the connection the DB is: 'dbMine.connect(rFileName, rRec)
rFilter[0] = 2
rFilter[1] = 'Name = M*'
rFilter[2] = 'Surname <> co*w'
say 'After defining a filter: 'dbMine.definefilter(rFilter)
/* Now, let's write a couple of records */
rArr[0,0] = 2 /* Number of records to be saved on disk */
rArr[1,1] = 'Max' /* First field of the first record. */
rArr[2,1] = 'Marsiglietti' /* Second field of the first record. */
rArr[1,2] = 'Mike' /* First field of the second record. */
rArr[2,2] = 'Cowlishaw' /* Second field of the second record. */
say 'The write operation reported: 'dbMine.saverec(rArr, "OVERWRITE")
say 'Now retrieving data sorted by name:'
/* Retrieve those records and display them on screen */
rArr2 = dbMine.loadrec("Name", "all", "1", 1)
/*
The former line uses "name" as the index.
Also, "1" means 1st record in the specified index.
*/
say ' '
/*
Let's build the top row of the db dump.
*/
rTemp3 = ' IDX Number.REC Number .'
loop iCount = 1 to rRec[0,0]
rTemp3 = rTemp3 || (rRec[iCount,1]).right(rRec[iCount,0],' ') || '.'
end
say rTemp3
/*
A little reminder: (useful for the following babele)
GENERIC LOADREC RETURN:
rArr2 = where records have been stored by loadrec.
rArr2[0,0] = how many records were returned? Here you know.
rArr2[0,1] = how many ACTIVE (not 'N') records were returned? (Not used here)
rArr2[n,m] = field 'n' of record 'm'; n,m start from 1.
If 'z' is the latest field:
rArr2[z+1, m] = status of the m-th record: active? ('Y' or 'N')
rArr2[z+2, m] = record position in the database
rArr2[z+3, m] = record position in the index used by the just issued loadrec
INFOS ON THE ARCHIVE:
rRec = structure of the archive.
rRec[0,0] = number of fields.
rRec[n,0] = length of the n-th field.
rRec[n,1] = name of the n-th field.
rRec[n,2] = indexing of the n-th field (NONE, ISAM, B+TREE). B+TREE Not yet implemented.
*/
if rArr2[0, 0] > 0 then
do
loop iCount = 1 to rArr2[0,0]
if rArr2[3, iCount] \='N' then /* If it's 'N' then it's deleted (shouldn't be any) */
rTemp2 = rArr2[rArr2[0,0]+3, iCount] /* IDX position */
rTemp2 = rTemp2.right(11, ' ')
rTemp = rTemp2 || '.' || (rArr2[4, iCount]).right(11, ' ') || '.' /* 4=REC pos */
loop iCount2 = 1 to rRec[0,0]
rTemp = rTemp || (rArr2[iCount2, iCount]).left(rRec[iCount2, 0], ' ') || '.'
end
say rTemp
end
end
say '\nNow deleting Mike!! (haha)'
rRec2[0]=1 /* How many rec to delete/undelete? */
rRec2[1]=2 /* Which one to delete/undelete? */
dbMine.delerec(rRec2, 1) /* 1 = Delete it */
rStats = dbMine.getdbstats()
say 'DB size: '||rStats[0]||' Record size: '||rStats[1]||' Records: '||rStats[2]||' Active records: '||rStats[3]
/* Retrieve those records and display them on screen */
rArr2 = dbMine.loadrec("Name", "all", "1", 1)
say ' '
say rTemp3 -- write the header that we built before.
if rArr2[0, 0] > 0 then
do
loop iCount = 1 to rArr2[0,0]
if rArr2[3, iCount] \='N' then /* If it's 'N' then it's deleted */
rTemp2 = rArr2[rArr2[0,0]+3, iCount] /* IDX position */
rTemp2 = rTemp2.right(11, ' ')
rTemp = rTemp2 || '.' || (rArr2[4, iCount]).right(11, ' ') || '.'
loop iCount2 = 1 to rRec[0,0]
rTemp = rTemp || (rArr2[iCount2, iCount]).left(rRec[iCount2, 0], ' ') || '.'
end
say rTemp
end
end
say '\nNow un-deleting Mike, changing Max to Massimiliano,'
say 'and retrieving elements sorted by surname:'
rRec2[0]=1 /* How many rec to delete/undelete? */
rRec2[1]=2 /* Which one to delete/undelete? */
dbMine.delerec(rRec2, 0) /* 0 = Undelete it */
rArr[0,0] = 1 /* Number of records to be modified */
rArr[0,1] = 1 /* Where has this record to be put? */
rArr[1,1] = 'Massimiliano' /* First field of the first record. */
rArr[2,1] = 'Marsiglietti' /* Second field of the first record. */
dbMine.modirec(rArr)
/* Retrieve those records and display them on screen */
rArr2 = dbMine.loadrec("Surname", "all", "1", 1)
say ' '
say rTemp3 -- write the header that we built before.
if rArr2[0, 0] > 0 then
do
loop iCount = 1 to rArr2[0,0]
if rArr2[3, iCount] \='N' then /* If it's 'N' then it's deleted */
rTemp2 = rArr2[rArr2[0,0]+3, iCount] /* IDX position */
rTemp2 = rTemp2.right(11, ' ')
rTemp = rTemp2 || '.' || (rArr2[4, iCount]).right(11, ' ') || '.'
loop iCount2 = 1 to rRec[0,0]
rTemp = rTemp || (rArr2[iCount2, iCount]).left(rRec[iCount2, 0], ' ') || '.'
end
say rTemp
end
end
/* We just got enough */
say '\nDisconnection returned: 'dbMine.disconnect()